#include "global.h"
#include <bits/stdc++.h>

using namespace std;

int transRes(void);
bool compFrc(cmpRes R1,cmpRes R2);
int printMinus(void);
int printPrint(void);

int printRes(void){
    printPrint();
    /*
    //redirect
    ofstream fout("calc.res");
    streambuf *oldcout;
    oldcout = cout.rdbuf(fout.rdbuf());
    printPrint();
    //redirect
    cout.rdbuf(oldcout);
    */
    return 0;
}

int printPrint(void)
{
    transRes();
    printMinus();
    cout<<endl;
    cout<<"T="<<endl<<"\t"<<TF<<" K"<<endl;
    cout<<"P="<<endl<<"\t"<<equ.p<<" Pa"<<endl;
    cout<<"Fractions of the combusition products:"<<endl;
    for(int j=0;j<equ.N;j++){
        cout<<"\t";
        cout<<cmbCmp[j].name<<":\t"<<cmbCmp[j].frc<<endl;
    }
    cout<<"Enthalpy="<<endl<<"\t"<<equ.hF<<" J/kg"<<endl;
    cout<<"Specific heat(p=const)="<<endl<<"\t"<<equ.cP<<" J/(kg*K)"<<endl;
    cout<<"Specific heat(V=const)="<<endl<<"\t"<<equ.cV<<" J/(kg*K)"<<endl;
    cout<<"Gamma ="<<endl<<"\t"<<equ.Gamma<<endl;
    cout<<"Molecular Weight="<<endl<<"\t"<<equ.molWeight<<" kg/mol"<<endl;
    cout<<"Velocity="<<endl<<"\t"<<equ.velocity<<" m/s"<<endl;
    for(int i=0;i<3;i++) cout<<endl;
    return 0;
}

int printPerf(void)
{
    printMinus();
    cout<<endl;
    cout<<"Specific impulse="<<endl;
    cout<<"\tSea level\t\tVacuum"<<endl;
    cout<<"\t"<<nozzleExit.velocity<<" m/s\t\t"<<vcmImpulse<<" m/s\t"<<endl;
    cout<<"Characteristic velocity="<<endl;
    cout<<"\t"<<charVel<<" m/s"<<endl;
    return 0;
}

int printMinus(void)
{
    for(int i=0;i<40;i++) cout<<"-";
    return 0;
}

int transRes(void){
    double temp=0;
    for(int j=0;j<equ.N;j++){
        temp+=equ.X[j];
    }
    for(int j=0;j<equ.N;j++){
        cmbCmp[j].frc=equ.X[j]/temp;
        cmbCmp[j].name=compound[equ.cmpIdx[j]].name;
    }
    sort(cmbCmp,cmbCmp+equ.N,compFrc);
    return 0;
}

bool compFrc(cmpRes R1,cmpRes R2)
{
    return R1.frc>R2.frc;
}

int printDSH(void)
{
    //cout<<"---------------------------"<<endl;
    cout<<"欢迎使用火箭发动机热力学计算程序。"<<endl;
    //cout<<"---------------------------"<<endl<<endl<<endl;
    //cout<<"--------------------------------------------------"<<endl;
    cout<<"此程序由北航宇航学院宇航推进系18级本科生狄思含编写。"<<endl;
    //cout<<"--------------------------------------------------"<<endl;
    cout<<"学号：18375442"<<endl<<"班号：181516"<<endl<<"手机：18710092661"<<endl;
    for(int i=0;i<3;i++) cout<<endl;
    return 0;
}
